package edu.xidian.bdilab.jrbigdata.controller.bank;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.service.bank.login.CheckInfoById;
import edu.xidian.bdilab.jrbigdata.service.bank.login.bankuserloginservice;
import edu.xidian.bdilab.jrbigdata.util.DecryptUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpSession;

@RestController
@CrossOrigin
@Api(tags = {"bankLogin-银行用户登录功能"})
public class BankLoginController {

    @Autowired
    public bankuserloginservice bankuserloginservice;
    @Autowired
    CheckInfoById checkInfoById;
    @RequestMapping(value = "bank/login", method = RequestMethod.POST)
    public ResponseResult enterprise_login(@RequestParam String name,
                                           @RequestParam String password,
                                           HttpSession session) {
        //HttpSession session=request.getSession();
//        System.out.println("sessionID="+session.getId());
        String md5Password = DecryptUtils.getMd5(password);
        ResponseResult responseResult= bankuserloginservice.responsResult(name,md5Password);
        if (responseResult.getMeta().getSuccess()){
            session.setAttribute("user_name",name);
//            System.out.println("user_name="+session.getAttribute("user_name"));
//            System.out.println("sessionID="+session.getId());
            return responseResult;
        }else {
            return responseResult;
        }
    }

    @PostMapping("bank/login/{userName}")
    public ResponseResult checkBankInfo(@PathVariable String userName){
        ResponseResult responseResult = new ResponseResult(true, " ", "查询成功");
        responseResult.setData(checkInfoById.checkInfoByUserName(userName));
        return responseResult;
    }
}
